<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="版税报告期间">
        <el-date-picker
          v-model="daterangePeriod"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="被授权人名" prop="nameAuthorizedPerson">
        <el-input
          v-model="queryParams.nameAuthorizedPerson"
          placeholder="请输入被授权人名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="权利人名" prop="nameRightsHolder">
        <el-input
          v-model="queryParams.nameRightsHolder"
          placeholder="请输入权利人名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理店名" prop="agency">
        <el-input
          v-model="queryParams.agency"
          placeholder="请输入代理店名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本期销售数量" prop="salesVolumePeriod">
        <el-input
          v-model="queryParams.salesVolumePeriod"
          placeholder="请输入本期销售数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:holders:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:holders:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:holders:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:holders:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      border
      stripe
      v-loading="loading"
      :data="holdersList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column
        label="版税报告期间"
        align="center"
        prop="period"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.period, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="被授权人名"
        align="center"
        prop="nameAuthorizedPerson"
      />
      <el-table-column label="合同号码" align="center" prop="contractNumber" />
      <el-table-column label="卷数" align="center" prop="numberRolls" />
      <el-table-column
        label="原作品名"
        align="center"
        prop="originalWorkTitle"
      />
      <el-table-column
        label="作品翻译书名"
        align="center"
        prop="titleTranslated"
      />
      <el-table-column
        label="权利人名"
        align="center"
        prop="nameRightsHolder"
      />
      <el-table-column label="代理店名" align="center" prop="agency" />
      <el-table-column
        label="翻译出版日"
        align="center"
        prop="translationPublicationDay"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.translationPublicationDay, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="合同开始日"
        align="center"
        prop="contractStartDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.contractStartDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="合同终止日"
        align="center"
        prop="contractExpirationDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.contractExpirationDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="本期印刷数量"
        align="center"
        prop="printingQuantity"
      />
      <el-table-column
        label="本期销售数量"
        align="center"
        prop="salesVolumePeriod"
      />
      <el-table-column
        label="本期坏书・赠书数量"
        align="center"
        prop="badGiftedBooks"
      />
      <el-table-column
        label="本期末库存"
        align="center"
        prop="inventoryEndPeriod"
      />
      <el-table-column
        label="本期末累計印刷数量"
        align="center"
        prop="accumulatedPrintingQuantity"
      />
      <el-table-column
        label="本期末累計销售数量"
        align="center"
        prop="accumulatedSalesQuantity"
      />
      <el-table-column
        label="本期末累计坏书・赠书数量"
        align="center"
        prop="badNumberBooks"
      />
      <el-table-column label="货币单位" align="center" prop="badUnit">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.currency"
            :value="scope.row.badUnit ? scope.row.badUnit.split(',') : []"
          />
        </template>
      </el-table-column>
      <el-table-column label="定价" align="center" prop="fixedPrice" />
      <el-table-column
        label="本期版版计算数量"
        align="center"
        prop="royaltyQuantity"
      />
      <el-table-column label="货币单位" align="center" prop="monetaryUnit" />
      <el-table-column
        label="本期销售/印刷金额"
        align="center"
        prop="salesPrintingAmount"
      />
      <el-table-column label="货币单位" align="center" prop="salesUnit" />
      <el-table-column
        label="本期发生版税金额"
        align="center"
        prop="royaltyAmount"
      />
      <el-table-column
        label="本期退货版税金额"
        align="center"
        prop="returnRoyaltyAmount"
      />
      <el-table-column label="货币单位" align="center" prop="returnUnit" />
      <el-table-column
        label="累计到前期已发生版税金額"
        align="center"
        prop="accumulatedRoyaltyAmount"
      />
      <el-table-column label="货币单位" align="center" prop="royaltyUnit" />
      <el-table-column
        label="累计已支付办税金额"
        align="center"
        prop="accumulatedRoyaltiesPaid"
      />
      <el-table-column label="货币单位" align="center" prop="royaltiesUnit" />
      <el-table-column
        label="累计到前期的预付款金额"
        align="center"
        prop="accumulatedPrepaymentBalance"
      />
      <el-table-column
        label="累计待沖抵版税金额"
        align="center"
        prop="accumulatedAmountRoyaltyOffset"
      />
      <el-table-column label="货币單位" align="center" prop="offsetAunit" />
      <el-table-column
        label="本期应支付版稅金额"
        align="center"
        prop="royaltiesPayable"
      />
      <el-table-column
        label="源泉徵收稅金额"
        align="center"
        prop="sourceCollectionAmount"
      />
      <el-table-column
        label="佣金金额"
        align="center"
        prop="commissionAmount"
      />
      <el-table-column
        label="应汇款金额"
        align="center"
        prop="amountRemitted"
      />
      <el-table-column
        label="汇款外方日期"
        align="center"
        prop="dateRemittanceForeign"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.dateRemittanceForeign, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:holders:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:holders:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改版税报告一览表对话框 -->
    <el-dialog
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      :title="title"
      :visible.sync="open"
      append-to-body
      width="800px"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <div class="container">
          <el-form-item class="option" label="版税报告期间" prop="period">
            <el-date-picker
              clearable
              v-model="form.period"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择版税报告期间"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item class="option" label="被授权人名" prop="nameAuthorizedPerson">
            <el-input
              v-model="form.nameAuthorizedPerson"
              placeholder="请输入被授权人名"
            />
          </el-form-item>
          <el-form-item class="option" label="合同号码" prop="contractNumber">
            <el-input
              v-model="form.contractNumber"
              placeholder="请输入合同号码"
            />
          </el-form-item>
       

        <el-form-item class="option" label="卷数" prop="numberRolls">
          <el-input v-model="form.numberRolls" placeholder="请输入卷数" />
        </el-form-item>
        <el-form-item class="option" label="原作品名" prop="originalWorkTitle">
          <el-input
            v-model="form.originalWorkTitle"
            placeholder="请输入原作品名"
          />
        </el-form-item>
        <el-form-item class="option" label="作品翻译书名" prop="titleTranslated">
          <el-input
            v-model="form.titleTranslated"
            placeholder="请输入作品翻译书名"
          />
        </el-form-item>
        <el-form-item class="option" label="权利人名" prop="nameRightsHolder">
          <el-input
            v-model="form.nameRightsHolder"
            placeholder="请输入权利人名"
          />
        </el-form-item>
        <el-form-item class="option" label="代理店名" prop="agency">
          <el-input v-model="form.agency" placeholder="请输入代理店名" />
        </el-form-item>
        <el-form-item class="option" label="翻译出版日" prop="translationPublicationDay">
          <el-date-picker
            clearable
            v-model="form.translationPublicationDay"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择翻译出版日"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="option" label="合同开始日" prop="contractStartDate">
          <el-date-picker
            clearable
            v-model="form.contractStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择合同开始日"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="option" label="合同终止日" prop="contractExpirationDate">
          <el-date-picker
            clearable
            v-model="form.contractExpirationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择合同终止日"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="option" label="本期印刷数量" prop="printingQuantity">
          <el-input
            v-model="form.printingQuantity"
            placeholder="请输入本期印刷数量"
          />
        </el-form-item>
        <el-form-item class="option" label="本期销售数量" prop="salesVolumePeriod">
          <el-input
            v-model="form.salesVolumePeriod"
            placeholder="请输入本期销售数量"
          />
        </el-form-item>
        <el-form-item class="option" label="本期坏书・赠书数量" prop="badGiftedBooks">
          <el-input
            v-model="form.badGiftedBooks"
            placeholder="请输入本期坏书・赠书数量"
          />
        </el-form-item>
        <el-form-item class="option" label="本期末库存" prop="inventoryEndPeriod">
          <el-input
            v-model="form.inventoryEndPeriod"
            placeholder="请输入本期末库存"
          />
        </el-form-item>
        <el-form-item
        class="option"
          label="本期末累計印刷数量"
          prop="accumulatedPrintingQuantity"
        >
          <el-input
            v-model="form.accumulatedPrintingQuantity"
            placeholder="请输入本期末累計印刷数量"
          />
        </el-form-item>
        <el-form-item
        class="option"
          label="本期末累計销售数量"
          prop="accumulatedSalesQuantity"
        >
          <el-input
            v-model="form.accumulatedSalesQuantity"
            placeholder="请输入本期末累計销售数量"
          />
        </el-form-item>
        <el-form-item class="option" label="本期末累计坏书・赠书数量" prop="badNumberBooks">
          <el-input
            v-model="form.badNumberBooks"
            placeholder="请输入本期末累计坏书・赠书数量"
          />
        </el-form-item>
        <el-form-item class="option" label="货币单位" prop="badUnit">
          <el-checkbox-group v-model="form.badUnit">
            <el-checkbox
              v-for="dict in dict.type.currency"
              :key="dict.value"
              :label="dict.value"
            >
              {{ dict.label }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item class="option" label="定价" prop="fixedPrice">
          <el-input v-model="form.fixedPrice" placeholder="请输入定价" />
        </el-form-item>
        <el-form-item class="option" label="本期版版计算数量" prop="royaltyQuantity">
          <el-input
            v-model="form.royaltyQuantity"
            placeholder="请输入本期版版计算数量"
          />
        </el-form-item>
        <el-form-item class="option" label="货币单位" prop="monetaryUnit">
          <el-input v-model="form.monetaryUnit" placeholder="请输入货币单位" />
        </el-form-item>
        <el-form-item class="option" label="本期销售/印刷金额" prop="salesPrintingAmount">
          <el-input
            v-model="form.salesPrintingAmount"
            placeholder="请输入本期销售/印刷金额"
          />
        </el-form-item>
        <el-form-item class="option" label="货币单位" prop="salesUnit">
          <el-input v-model="form.salesUnit" placeholder="请输入货币单位" />
        </el-form-item>
        <el-form-item class="option" label="本期发生版税金额" prop="royaltyAmount">
          <el-input
            v-model="form.royaltyAmount"
            placeholder="请输入本期发生版税金额"
          />
        </el-form-item>
        <el-form-item class="option" label="本期退货版税金额" prop="returnRoyaltyAmount">
          <el-input
            v-model="form.returnRoyaltyAmount"
            placeholder="请输入本期退货版税金额"
          />
        </el-form-item>
        <el-form-item class="option" label="货币单位" prop="returnUnit">
          <el-input v-model="form.returnUnit" placeholder="请输入货币单位" />
        </el-form-item>
        <el-form-item
        class="option"
          label="累计到前期已发生版税金額"
          prop="accumulatedRoyaltyAmount"
        >
          <el-input
            v-model="form.accumulatedRoyaltyAmount"
            placeholder="请输入累计到前期已发生版税金額"
          />
        </el-form-item>
        <el-form-item class="option" label="货币单位" prop="royaltyUnit">
          <el-input v-model="form.royaltyUnit" placeholder="请输入货币单位" />
        </el-form-item>
        <el-form-item
        class="option"
          label="累计已支付办税金额"
          prop="accumulatedRoyaltiesPaid"
        >
          <el-input
            v-model="form.accumulatedRoyaltiesPaid"
            placeholder="请输入累计已支付办税金额"
          />
        </el-form-item>
        <el-form-item class="option" label="货币单位" prop="royaltiesUnit">
          <el-input v-model="form.royaltiesUnit" placeholder="请输入货币单位" />
        </el-form-item>
        
        <el-form-item
        class="option"
          label="累计到前期的预付款金额"
          prop="accumulatedPrepaymentBalance"
        >
          <el-input
            v-model="form.accumulatedPrepaymentBalance"
            placeholder="请输入累计到前期的预付款金额"
          />
        </el-form-item>
        <el-form-item
        class="option"
          label="累计待沖抵版税金额"
          prop="accumulatedAmountRoyaltyOffset"
        >
          <el-input
            v-model="form.accumulatedAmountRoyaltyOffset"
            placeholder="请输入累计待沖抵版税金额"
          />
        </el-form-item>
        <el-form-item class="option" label="货币單位" prop="offsetAunit">
          <el-input v-model="form.offsetAunit" placeholder="请输入货币單位" />
        </el-form-item>
        <el-form-item label="本期应支付版稅金额" prop="royaltiesPayable">
          <el-input
            v-model="form.royaltiesPayable"
            placeholder="请输入本期应支付版稅金额"
          />
        </el-form-item>
        <el-form-item class="option" label="源泉徵收稅金额" prop="sourceCollectionAmount">
          <el-input
            v-model="form.sourceCollectionAmount"
            placeholder="请输入源泉徵收稅金额"
          />
        </el-form-item>
        <el-form-item class="option" label="佣金金额" prop="commissionAmount">
          <el-input
            v-model="form.commissionAmount"
            placeholder="请输入佣金金额"
          />
        </el-form-item>
        <el-form-item class="option" label="应汇款金额" prop="amountRemitted">
          <el-input
            v-model="form.amountRemitted"
            placeholder="请输入应汇款金额"
          />
        </el-form-item>
        <el-form-item class="option" label="汇款外方日期" prop="dateRemittanceForeign">
          <el-date-picker
            clearable
            v-model="form.dateRemittanceForeign"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择汇款外方日期"
          >
          </el-date-picker>
        </el-form-item>
      </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listHolders,
  getHolders,
  delHolders,
  addHolders,
  updateHolders,
} from "@/api/system/holders";

export default {
  name: "Holders",
  dicts: ["currency"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 版税报告一览表表格数据
      holdersList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 汇款外方日期时间范围
      daterangePeriod: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        period: null,
        nameAuthorizedPerson: null,
        nameRightsHolder: null,
        agency: null,
        salesVolumePeriod: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询版税报告一览表列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangePeriod && "" != this.daterangePeriod) {
        this.queryParams.params["beginPeriod"] = this.daterangePeriod[0];
        this.queryParams.params["endPeriod"] = this.daterangePeriod[1];
      }
      listHolders(this.queryParams).then((response) => {
        this.holdersList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        period: null,
        nameAuthorizedPerson: null,
        contractNumber: null,
        numberRolls: null,
        originalWorkTitle: null,
        titleTranslated: null,
        nameRightsHolder: null,
        agency: null,
        translationPublicationDay: null,
        contractStartDate: null,
        contractExpirationDate: null,
        printingQuantity: null,
        salesVolumePeriod: null,
        badGiftedBooks: null,
        inventoryEndPeriod: null,
        accumulatedPrintingQuantity: null,
        accumulatedSalesQuantity: null,
        badNumberBooks: null,
        badUnit: [],
        fixedPrice: null,
        royaltyQuantity: null,
        monetaryUnit: null,
        salesPrintingAmount: null,
        salesUnit: null,
        royaltyAmount: null,
        returnRoyaltyAmount: null,
        returnUnit: null,
        accumulatedRoyaltyAmount: null,
        royaltyUnit: null,
        accumulatedRoyaltiesPaid: null,
        royaltiesUnit: null,
        accumulatedPrepaymentBalance: null,
        accumulatedAmountRoyaltyOffset: null,
        offsetAunit: null,
        royaltiesPayable: null,
        sourceCollectionAmount: null,
        commissionAmount: null,
        amountRemitted: null,
        dateRemittanceForeign: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangePeriod = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加版税报告一览表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getHolders(id).then((response) => {
        this.form = response.data;
        this.form.badUnit = this.form.badUnit.split(",");
        this.open = true;
        this.title = "修改版税报告一览表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.badUnit = this.form.badUnit.join(",");
          if (this.form.id != null) {
            updateHolders(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHolders(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除版税报告一览表编号为"' + ids + '"的数据项？')
        .then(function () {
          return delHolders(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/holders/export",
        {
          ...this.queryParams,
        },
        `holders_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss">
// .option {
//   width: 33%;
// }
// .container {
//     display: flex;
//     flex-wrap: wrap;
//     justify-content: space-between;
//   }
</style>
